def check(n):
    for i in range(2,n):
        if n%i == 0:
            return False
    else:
        return True
try:
    a,b,c = input().split()
    L = {"zero":0,"one":1,"two":2, "three":3, "four":4, "five":5, "six":6, "seven":7, "eight":8, "nine":9}
    n = L[a]*100+L[b]*10+L[c]
    if len(str(n)) != 3:
        print(1/0)
        
    countup = [0,0]
    countdown = [0,0]
    
    for i in range(n,n*2+1):
        if check(i):
            countup[1] = i
            break
        else:
            countup[0] += 1
            
    for i in range(n,99,-1):
        if check(i):
            countdown[1] = i
            break
        else:
            countdown[0] += 1
            
    if countdown[0] <= countup[0]:
        print(countdown[1])
    else:
        print(countup[1])
except:
    print("wrong input")